$(function () {
    $(".commit").click(function () {
        var flag=true;//判断是否可以注册
        var $devCode=$("#devCode");
        var $devName=$("#devName");
        var $devPassword=$("#devPassword");
        var $devEmail=$("#devEmail");
        var $devInfo=$("#devInfo");

        var $codespan=$devCode.next();
        var $devNamespan=$devName.next();
        var $devPasswordspan=$devPassword.next();
        var $devEmailspan=$devEmail.next();
        var $devInfospan=$devInfo.next();
        if ($devCode.val()==null||$devCode.val()==""){
            $codespan.html("账号不能为空！").css("color","red");
            flag=false;
        }else {
            $.ajax({
                "url": "/Dev_user/dev_user/isRepeat",
                "type": "POST",
                "data": "devCode="+$devCode.val(),
                "dataType": "json",
                "success": function (data) {
                    if (data=="exist"){//账号存在，不能进行注册
                        $codespan.html("账号已被注册！").css("color","red");
                        flag=false;
                    }else{
                        $codespan.html("账号可以注册！").css("color","green");
                        flag=true;
                    }

                }
            })
        }
        if ($devName.val()==null||$devName.val()==""){
            $devNamespan.html("昵称不能为空！").css("color","red");
            flag=false;
        }else{
            $devNamespan.html("");
        }
        if ($devPassword.val()==null||$devPassword.val()==""){
            $devPasswordspan.html("密码不能为空！").css("color","red");
            flag=false;
        }else{
            $devPasswordspan.html("");
        }
        if ($devEmail.val()==null||$devEmail.val()==""){
            $devEmailspan.html("邮箱不能为空！").css("color","red");
            flag=false;
        }else{
            $devEmailspan.html("");
        }
        if ($devInfo.val()==null||$devInfo.val()==""){
            $devInfospan.html("信息不能为空！").css("color","red");
            flag=false;
        }else{
            $devInfospan.html("");
        }
        if (flag){
            $.ajax({
                "url": "/Dev_user/dev_user/addDevSave",
                "type": "POST",
                "data": "devCode="+$devCode.val()+"&devName="+$devName.val()+"&devPassword="+$devPassword.val()+"&devEmail="+$devEmail.val()+"&devInfo="+$devInfo.val(),
                "dataType": "json",
                "success": function (data) {
                    if (data=="true"){
                        alert("添加成功！");
                        open("/Dev_user/dev_user/list","_self");
                    }else{
                        alert("添加失败！");
                    }
                }
            })
        }
    })
})